// url.js

const test_ip = 'http://localhost'
const test_port = 8000;

function construcUrl(url) {
    return `${test_ip}:${test_port}${url}`;
}

// get the filter criteria for the post list.
const postListFilter = {
    fields: ['id', 'title', 'author', 'vote', 'updateAt'],
    limit: 10,
    order: 'updatedAt DESC',
    include: 'authorPointer',
    includeFilter: {
        user: {
            fields: ['id', 'username']
        }
    }
};

// get the filter criteria for the detail of post.
const postByIdFilter = id => ({
    fields: ['id', 'title', 'author', 'vote', 'updateAt', 'content'],
    where: {id: id},
    include: 'authorPointer',
    includeFilter: {
        user: {
            fields: ['id', 'username']
        }
    }
});

// get the filter criteria for the comment list
const commentListFilter = postId => ({
    fields: ['id', 'author', 'updateAt', 'content'],
    where: {post: postId},
    limit: 20,
    order: 'updateAt DESC',
    include: 'authorPointer',
    includeFilter: {
        user: {
            fields: ['id', 'username']
        }
    }
});

function encodeFilter(filter) {
    return encodeURIComponent(JSON.stringify(filter));
}

export default {
    // login
    login: () => construcUrl('/user/login'),
    // get post list
    getPostList: () => construcUrl(`/post/getall`),
    // get post detail
    getPostById: id => construcUrl(`/post/get?post_id=${id}}`),
    // create post
    createPost: () => construcUrl('/post/create'),
    // update post
    updatePost: id =>construcUrl(`/post/${id}`),
    // get comment list
    getCommentList: postId => construcUrl(`/comment/get?post_id=${(postId)}`),
    // create comment
    createComment: () => construcUrl('/comment')
};
